"""
Mixer classes for easier access.
$Id: mixer.py,v 1.3 2004/11/27 09:57:34 krawczyk Exp $

mixer -- Global mixer variable, it is created after calling Init()
"""

import pygame, config

class Mixer:
    """Mixer class which is ued later on, has basic methods."""
    def fadeout(self, time):
        "Fadeout music in time secondes"
        pass
    def load(self, name):
        "Load a Music"
        pass
    def play(self, num = -1):
        "Play Music num times"
        pass
    def loadsnd(self, name):
        "Load a sound effect aka sound file."
        raise NotImplementedError

class DummySound:
    """Ignores every event, so that we do not distinguish between available and no available mixer."""
    def play(self):
        pass

class DummyMixer(Mixer):
    """DummyMixer ignores loadsnd and gives a Dummysound"""
    def loadsnd(self, name):
        return DummySound()


class SDLMixer(Mixer):
    def fadeout(self, time):
        pygame.mixer.music.fadeout(time)
    def load(self, name):
        pygame.mixer.music.load(name)
    def play(self, num = -1):
        pygame.mixer.music.play(num)
    def loadsnd(self, name):
        return pygame.mixer.Sound(name)

def Init():
    "Initialise Mixer, get Dummy if no SDL Mixer available."
    if pygame.mixer.get_init() == None:
        print "Warning, no Mixer available!"
        config.mixer = DummyMixer()
    else:
        config.mixer = SDLMixer()
    global mixer
    mixer = config.mixer

